<extend name="Index/index"/>

<block name="register">

    <form action="{{:U('User/confirmOrder')}}" method="post">

    <div class="container">

        <div class="row mt10 address">
            <h3><b>购物车</b></h3>
        </div>
        <if condition="empty($cartList)">
            <a href="{{:U('Index/index')}}" class="text-center text-danger" style="font-size: 30px">你的购物车是空的哦,去添些商品吧!!!</a>
            <div style="margin-top: 150px"></div>
        <else/>
            <div class="row col-md-12 mt30">

                <table class="row col-md-12 text-center table" cellpadding="0" cellspacing="0">
                    <tr>
                        <th class="text-center">
                            <label><em class="text-danger">全选&nbsp;&nbsp;</em><input type="checkbox" id="checkAll" checked="checked"></label>
                        </th>
                        <th class="text-center">商品图片</th>
                        <th class="text-center">商品名称</th>
                        <th class="text-center">商品价格</th>
                        <th class="text-center">商品数量</th>
                        <th class="text-center">小计</th>
                        <th class="text-center">操作</th>
                    </tr>
                    <foreach name="cartList" item="item">

                        <tr>
                            <td class="col-md-1">
                                <input type="checkbox" id="box_{{$item.id}}" checked="checked">
                            </td>
                            <!--商品图片-->
                            <td class="col-md-2">
                                <a href="{{:U('Index/goodsDetails',array('id'=>$item['id']))}}">
                                    <img src="{{:get_img_url('__ROOT__/Uploads/GoodsImg/',$item['img'],50)}}">
                                </a>
                            </td>
                            <!--商品名称-->
                            <td class="col-md-2">
                                <a href="{{:U('Index/goodsDetails',array('id'=>$item['id']))}}">
                                    {{:subtext($item['goods_name'],20)}}
                                </a>
                            </td>
                            <!--商品价格-->
                            <td class="col-md-1">
                                <span class="glyphicon glyphicon-jpy" style="font-size: 20px;color: red;"></span>
                                <span id="price{{$item.id}}" style="font-size: 15px;color: red">{{$item.price}}</span>
                            </td>
                            <!--商品库存-->
                            <input type="hidden" id="num{{$item.id}}" value="{{$item.goods_num}}">
                            <!--商品数量-->
                            <td class="col-md-2">
                                            <span class="price">
                                                <div class="col-md-3  btn btn-default" onclick="minusCart('{{$item.id}}')" id="minus{{$item.id}}">▬</div>
                                                <div class="col-md-6">
                                                    <input type="number" id="qty{{$item.id}}" value="{{$item.num}}" class="form-control text-center" onchange="change_num_cart('{{$item.id}}')">
                                                </div>
                                                <div class="col-md-3 btn btn-default" onclick="plusCart('{{$item.id}}')">✚</div>
                                            </span>
                            </td>
                            <!--商品小计-->
                            <td class="col-md-2">
                                <span class="glyphicon glyphicon-jpy" style="font-size: 20px;color: red;"></span>
                                <span id="total{{$item.id}}" style="font-size: 15px;color: red">{{$item['num']*$item['price']}}</span>
                            </td>
                            <td class="col-md-2">
                                <a href="{{:U('User/delCart',array('goods_id'=>$item['id']))}}" class="text-info">删除</a>
                            </td>
                        </tr>
                    </foreach>
                    <tr>
                        <td colspan="4" class="text-right">
                            <a class="btn btn-danger" href="{{:U('User/delAllCart')}}">清空购物车</a>
                        </td>
                        <td colspan="1">
                            <span style="font-size: 15px" class="text-danger">商品总价格:</span>
                        </td>
                        <td colspan="1">
                            <span class="glyphicon glyphicon-jpy text-danger" style="font-size: 25px;"></span>
                            <span style="font-size: 15px;font-weight: bold" class="text-danger" id="total_price">0</span>
                            <span style="font-size: 15px;font-weight: bold" class="text-danger" >元</span>
                        </td>
                        <td colspan="1" class="text-right">
                            <input type="hidden" name="act" value="cart">
                            <input type="hidden" id="allGoodsId" name="goods_id">
                            <input class="btn btn-success" type="submit" value="提交订单">
                        </td>
                    </tr>
                </table>

            </div>
        </if>
    </div>
    </form>
    <script src="__PUBLIC__/Home/js/home.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/Home/css/home.css">
    <script>
        //购物车总价格
        allSum();
        //把所有选中的商品id放到表单中
        allGoods();
    </script>
</block>